package com.example.auth.repository;

import com.example.auth.entity.TaskSubmission;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

/**
 * Task Submission Data Access Layer
 */
@Repository
public interface TaskSubmissionRepository extends JpaRepository<TaskSubmission, Long> {

    /**
     * Find submission records by task ID
     */
    List<TaskSubmission> findByTaskId(Long taskId);

    /**
     * Find submission records by task ID and submitter ID
     */
    List<TaskSubmission> findByTaskIdAndSubmitterId(Long taskId, Long submitterId);

    /**
     * Find the newest submission record for a task
     */
    Optional<TaskSubmission> findFirstByTaskIdOrderBySubmissionTimeDesc(Long taskId);

    /**
     * Find all submission records for a user
     */
    List<TaskSubmission> findBySubmitterId(Long submitterId);

    /**
     * Count the number of submissions for a task
     */
    long countByTaskId(Long taskId);

    /**
     * Check if there are any submission records for a task
     */
    boolean existsByTaskId(Long taskId);

    /**
     * Count the number of tasks with submission records, given a list of task IDs
     */
    long countByTaskIdIn(List<Long> taskIds);
}